import {BasicColumn, FormSchema} from '/@/components/Table';
import {h} from "@vue/runtime-core";
import {Tag} from "ant-design-vue";
import {DescItem} from "/@/components/Description";

export const columns: BasicColumn[] = [
  {
    title: '订单号',
    dataIndex: 'orderNo',
    width: 220,
    slots: {customRender: 'orderNo'}
  },
  {
    title: '商户名称',
    dataIndex: 'mchName',
  },
  {
    title: '支付方式',
    dataIndex: 'wayCode',
  },
  {
    title: '支付金额',
    dataIndex: 'amount',
    customRender: ({record}) => {
      return record.amount / 100;
    },
  },
  {
    title: '手续费',
    dataIndex: 'feeAmount',
    customRender: ({record}) => {
      return record.feeAmount / 100;
    },
  },
  {
    title: '退款金额',
    dataIndex: 'refundAmount',
    customRender: ({record}) => {
      return record.refundAmount / 100;
    },
  },
  {
    title: '订单状态',
    dataIndex: 'orderStatus',
    customRender: ({record}) => {
      let color = 'volcano';
      let text = '';
      switch (record.orderStatus) {
        case 0:
          color = 'blue';
          text = '订单生成';
          break;
        case 1:
          color = 'orange';
          text = '支付中';
          break;
        case 2:
          color = 'green';
          text = '支付成功';
          break;
        case 3:
          text = '支付失败';
          break;
        case 4:
          text = '已撤销';
          break;
        case 5:
          text = '支付成功';
          break;
        case 6:
          color = '';
          text = '订单关闭';
          break;
        default:
          text = '未知';
      }
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '回调状态',
    dataIndex: 'notifyStatus',
    customRender: ({record}) => {
      const status = record.notifyStatus;
      const enable = ~~status === 1;
      const color = enable ? 'green' : 'orange';
      const text = enable ? '已发送' : '未发送';
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '订单分账状态',
    dataIndex: 'divisionStatus',
    customRender: ({record}) => {
      let color = '';
      let text = '';
      if (record.divisionStatus === 0) {
        return '-';
      } else if (record.divisionStatus === 1) {
        color = 'orange';
        text = '待分账';
      } else if (record.divisionStatus === 2) {
        color = 'red';
        text = '分账处理中';
      } else if (record.divisionStatus === 3) {
        color = 'green';
        text = '任务已结束';
      } else {
        return '未知状态';
      }
      return h(Tag, {color: color}, () => text);
    },
  },
  {
    title: '下单时间',
    dataIndex: 'createTime',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'orderNo',
    label: '订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'outTradeNo',
    label: '商户订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'channelOrderNo',
    label: '渠道订单号',
    component: 'Input',
    colProps: {span: 6},
  },
  {
    field: 'orderStatus',
    label: '订单状态',
    component: 'Select',
    componentProps: {
      options: [
        {label: '订单生成', value: 0},
        {label: '支付中', value: 1},
        {label: '支付成功', value: 2},
        {label: '支付失败', value: 3},
        {label: '已撤销', value: 4},
        {label: '已退款', value: 5},
        {label: '订单关闭', value: 6},
      ],
    },
    colProps: {span: 6},
  },
  {
    field: 'notifyStatus',
    label: '回调状态',
    component: 'Select',
    componentProps: {
      options: [
        {label: '未发送', value: 0},
        {label: '已发送', value: 1},
      ],
    },
    colProps: {span: 6},
  },
  {
    field: 'refundStatus',
    label: '退款状态',
    component: 'Select',
    componentProps: {
      options: [
        {label: '未退款', value: 0},
        {label: '部分退款', value: 1},
        {label: '全额退款', value: 2},
      ],
    },
    colProps: {span: 6},
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: 'ID',
    component: 'Input',
    show: false,
  },
  {
    field: 'orderNo',
    label: '订单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    required: true,
  },
  {
    field: 'isvNo',
    label: '服务商号',
    component: 'Input',
    required: true,
  },
  {
    field: 'appId',
    label: '应用ID',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchName',
    label: '商户名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'mchType',
    label: '类型: 1-普通商户, 2-特约商户(服务商模式)',
    component: 'Input',
    required: true,
  },
  {
    field: 'outTradeNo',
    label: '商户订单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'ifCode',
    label: '支付接口代码',
    component: 'Input',
    required: true,
  },
  {
    field: 'wayCode',
    label: '支付方式代码',
    component: 'Input',
    required: true,
  },
  {
    field: 'amount',
    label: '支付金额,单位分',
    component: 'Input',
    required: true,
  },
  {
    field: 'feeRate',
    label: '手续费费率快照',
    component: 'Input',
    required: true,
  },
  {
    field: 'feeAmount',
    label: '手续费,单位分',
    component: 'Input',
    required: true,
  },
  {
    field: 'currency',
    label: '三位货币代码,人民币:CNY',
    component: 'Input',
    required: true,
  },
  {
    field: 'orderStatus',
    label: '订单状态: 0-订单生成, 1-支付中, 2-支付成功, 3-支付失败, 4-已撤销, 5-已退款, 6-订单关闭',
    component: 'Input',
    required: true,
  },
  {
    field: 'notifyStatus',
    label: '回调状态, 0-未发送,  1-已发送',
    component: 'Input',
    required: true,
  },
  {
    field: 'clientIp',
    label: '客户端IP',
    component: 'Input',
    required: true,
  },
  {
    field: 'subject',
    label: '商品标题',
    component: 'Input',
    required: true,
  },
  {
    field: 'body',
    label: '商品描述信息',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelExtra',
    label: '特定渠道发起额外参数',
    component: 'Input',
  },
  {
    field: 'channelUser',
    label: '渠道用户标识,如微信openId,支付宝账号',
    component: 'Input',
    required: true,
  },
  {
    field: 'channelOrderNo',
    label: '渠道订单号',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundStatus',
    label: '退款状态: 0-未发生实际退款, 1-部分退款, 2-全额退款',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundTimes',
    label: '退款次数',
    component: 'Input',
    required: true,
  },
  {
    field: 'refundAmount',
    label: '退款总金额,单位分',
    component: 'Input',
    required: true,
  },
  {
    field: 'divisionMode',
    label: '订单分账模式：0-该笔订单不允许分账, 1-支付成功按配置自动完成分账, 2-商户手动分账(解冻商户金额)',
    component: 'Input',
    required: true,
  },
  {
    field: 'divisionStatus',
    label: '订单分账状态：0-未发生分账, 1-等待分账任务处理, 2-分账处理中, 3-分账任务已结束(不体现状态)',
    component: 'Input',
    required: true,
  },
  {
    field: 'divisionLastTime',
    label: '最新分账时间',
    component: 'Input',
  },
  {
    field: 'errCode',
    label: '渠道支付错误码',
    component: 'Input',
  },
  {
    field: 'errMsg',
    label: '渠道支付错误描述',
    component: 'Input',
  },
  {
    field: 'extParam',
    label: '商户扩展参数',
    component: 'Input',
  },
  {
    field: 'notifyUrl',
    label: '异步通知地址',
    component: 'Input',
  },
  {
    field: 'returnUrl',
    label: '页面跳转地址',
    component: 'Input',
  },
  {
    field: 'expiredTime',
    label: '失效时间',
    component: 'Input',
  },
  {
    field: 'successTime',
    label: '支付成功时间',
    component: 'Input',
  },
];

export const detailSchema: DescItem[] = [
  {
    field: 'mchName',
    label: '商户名称',
  },
  {
    field: 'mchNo',
    label: '商户号',
  },
  {
    field: 'mchType',
    label: '商户类型',
    render: (value) => {
      return value === 2 ? '特约商户' : '普通商户';
    },
  },
  {
    field: 'isvNo',
    label: '服务商号',
  },
  {
    field: 'appId',
    label: '应用ID',
  },
  {
    field: 'orderNo',
    label: '订单号',
  },
  {
    field: 'outTradeNo',
    label: '商户订单号',
  },
  {
    field: 'ifCode',
    label: '支付渠道',
  },
  {
    field: 'wayCode',
    label: '支付方式',
  },
  {
    field: 'amount',
    label: '支付金额',
    render: (value) => {
      return value / 100;
    },
  },
  {
    field: 'feeRate',
    label: '手续费费率',
  },
  {
    field: 'feeAmount',
    label: '手续费',
    render: (value) => {
      return value / 100;
    },
  },
  {
    field: 'currency',
    label: '货币代码',
  },
  {
    field: 'orderStatus',
    label: '订单状态',
    render: (value) => {
      let text = '';
      switch (value) {
        case 0:
          text = '订单生成';
          break;
        case 1:
          text = '支付中';
          break;
        case 2:
          text = '支付成功';
          break;
        case 3:
          text = '支付失败';
          break;
        case 4:
          text = '已撤销';
          break;
        case 5:
          text = '支付成功';
          break;
        case 6:
          text = '订单关闭';
          break;
        default:
          text = '未知';
      }
      return text;
    },
  },
  {
    field: 'notifyStatus',
    label: '回调状态',
    render: (value) => {
      return value === 1 ? '已发送' : '未发送';
    },
  },
  {
    field: 'errCode',
    label: '渠道支付错误码',
  },
  {
    field: 'errMsg',
    label: '渠道支付错误描述',
  },
  {
    field: 'extParam',
    label: '商户扩展参数',
  },
  {
    field: 'expiredTime',
    label: '失效时间',
  },
  {
    field: 'successTime',
    label: '支付成功时间',
  },
];

export const extendSchema: DescItem[] = [
  {
    field: 'clientIp',
    label: '客户端IP',
  },
  {
    field: 'subject',
    label: '商品标题',
  },
  {
    field: 'body',
    label: '商品描述信息',
  },
  {
    field: 'channelExtra',
    label: '特定渠道发起额外参数',
  },
  {
    field: 'channelUser',
    label: '渠道用户标识',
  },
  {
    field: 'channelOrderNo',
    label: '渠道订单号',
  },
  {
    field: 'refundStatus',
    label: '退款状态',
    render: (value) => {
      let text = '';
      switch (value) {
        case 0:
          text = '未退款';
          break;
        case 1:
          text = '部分退款';
          break;
        case 2:
          text = '全额退款';
          break;
        default:
          text = '-';
      }
      return text;
    },
  },
  {
    field: 'refundTimes',
    label: '退款次数',
  },
  {
    field: 'refundAmount',
    label: '退款金额',
    render: (value) => {
      return value / 100;
    },
  },
  {
    field: 'notifyUrl',
    label: '异步通知地址',
  },
  {
    field: 'returnUrl',
    label: '页面跳转地址',
  },
];

export const divisionSchema: DescItem[] = [
  {
    field: 'divisionMode',
    label: '分账模式',
    render: (value) => {
      let text = '';
      switch (value) {
        case 0:
          text = '订单不允许分账';
          break;
        case 1:
          text = '自动完成分账';
          break;
        case 2:
          text = '商户手动分账';
          break;
        default:
          text = '-';
      }
      return text;
    },
  },
  {
    field: 'divisionStatus',
    label: '分账状态',
    render: (value) => {
      let text = '';
      switch (value) {
        case 0:
          text = '未分账';
          break;
        case 1:
          text = '等处理';
          break;
        case 2:
          text = '分账处理中';
          break;
        case 3:
          text = '任务已结束';
          break;
        default:
          text = '-';
      }
      return text;
    },
  },
  {
    field: 'divisionLastTime',
    label: '最新分账时间',
  },
];
